<?php

class apidefinition_ModuleController extends Zend_Controller_Action
{
  function init() {
  	header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
	header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    $this->getHelper('viewRenderer')->setNoRender();
  }

  function createAction() {
    require_once('apidefinition/objects/module.php');
    try{
	  $results = APIDefinition_Object_Module::create($this->_getAllParams());
    } catch(APIDefinition_Object_Exception $e) {
      $data['status'] = 	'KO';
      $data['error']['num'] = 	$e->getCode();
      $data['error']['message'] = 	$e->getMessage();
 	  echo serialize($data);
      return;
    }
	$data['status'] = 	'OK';
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
    return;
  }
  
  function listAction() {
    require_once('apidefinition/objects/module.php');
    $results = APIDefinition_Object_Module::listing();
    $data['modules'] = $results;
    
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
  }
  
  function getAction() {
    require_once('apidefinition/objects/module.php');
    try {
      $module = new APIDefinition_Object_Module($this->_getParam('name'));
      $resModule = $module->asArray();
    } catch(APIDefinition_Object_Exception $e) {
      $data['status'] = 	'KO';
      $data['error']['num'] = 	$e->getCode();
      $data['error']['message'] = 	$e->getMessage();
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
      return;
    }
    
    //We list the different controllers of the module
    require_once('apidefinition/objects/controller.php');
    $resControllers = APIDefinition_Object_Controller::listing($module->getName());
    
    
	$data['status'] = 	'OK';
	$data['module'] = $resModule;
	$data['controllers'] = $resControllers;
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
    return;  	
  }

} //End class


?>